package edu.gmu.atelier.generic;

import edu.gmu.atelier.generic.AbstractMatrix;
import java.util.List;

/**
 * Utility matrix operations wrt RealVector arrays.
 * @author James H. Pope
 */
public class RealVectorUtil
{
//    public static void mulAdd(int startCol, RealVector[] a, int fromRow, double multiplier, int toRow)
//    {
//        for (int j = startCol; j < a.length; j++)
//        {
//            a[j].components[toRow] += a[j].components[fromRow]*multiplier;
//        }
//    }
    
    public static void mulAdd(int startCol, List<RealVector> a, int fromRow, double multiplier, int toRow)
    {
        for (int j = startCol; j < a.size(); j++)
        {
            a.get(j).elements[toRow] += a.get(j).elements[fromRow]*multiplier;
        }
    }
    
//    public static void swap(RealVector[] a, int row1, int row2)
//    {
//        for (int j = 0; j < a.length; j++)
//        {
//            double vc = a[j].components[row1];
//            a[j].components[row1] = a[j].components[row2];
//            a[j].components[row2] = vc;
//        }
//    }
    
    public static void swap(List<RealVector> a, int row1, int row2)
    {
        for (int j = 0; j < a.size(); j++)
        {
            double vc = a.get(j).elements[row1];
            a.get(j).elements[row1] = a.get(j).elements[row2];
            a.get(j).elements[row2] = vc;
        }
    }
    
    public static void swap(AbstractMatrix<RealVector> m, int row1, int row2)
    {
        List<RealVector> a = m.getVectors();
        for (int j = 0; j < a.size(); j++)
        {
            double vc = a.get(j).elements[row1];
            a.get(j).elements[row1] = a.get(j).elements[row2];
            a.get(j).elements[row2] = vc;
        }
    }
}
